home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 1.iso / HENSA / MATHS / PLPLOT / PLPLOT.ZIP / examples / C / x11c.c < prev    next >
C/C++ Source or Header  |  1994-06-30  |  3KB  |  110 lines

  1. /* $Id: x11c.c,v 1.9 1994/06/30 17:57:46 mjl Exp $
  2.  * $Log: x11c.c,v $
  3.  * Revision 1.9  1994/06/30  17:57:46  mjl
  4.  * All C example programs: made another pass to eliminate warnings when using
  5.  * gcc -Wall.  Lots of cleaning up: got rid of includes of math.h or string.h
  6.  * (now included by plplot.h), eliminated redundant casts, put in more
  7.  * uniform comments, and other minor changes.
  8.  *
  9.  * Revision 1.8  1994/03/30  07:21:55  mjl
  10.  * Changes to all C example programs: special handling for malloc re: header
  11.  * files eliminated, include of stdio.h and stdlib.h eliminated (now done
  12.  * by plplot.h), include of "plplot.h" changed to <plplot.h> to enable
  13.  * simpler builds by the general user, some cleaning up also.
  14. */
  15.  
  16. /*    x11c.c
  17.  
  18.     Mesh plot demo.
  19. */
  20.  
  21. #include <plplot.h>
  22.  
  23. #define XPTS    35        /* Data points in x */
  24. #define YPTS    46        /* Datat points in y */
  25.  
  26. static int opt[] =
  27. {1, 2, 3, 3};
  28.  
  29. static PLFLT alt[] =
  30. {60.0, 20.0, 60.0, 60.0};
  31.  
  32. static PLFLT az[] =
  33. {30.0, 60.0, 120.0, 160.0};
  34.  
  35. static char *title[4] =
  36. {
  37.     "#frPLplot Example 11 - Alt=60, Az=30, Opt=1",
  38.     "#frPLplot Example 11 - Alt=20, Az=60, Opt=2",
  39.     "#frPLplot Example 11 - Alt=60, Az=120, Opt=3",
  40.     "#frPLplot Example 11 - Alt=60, Az=160, Opt=3"
  41. };
  42.  
  43. /* Utility macros */
  44.  
  45. #ifndef PI
  46. #define PI    3.1415926535897932384
  47. #endif
  48.  
  49. /*----------------------------------------------------------------------*\
  50.  * main
  51.  *
  52.  * Does a series of mesh plots for a given data set, with different
  53.  * viewing options in each plot.
  54. \*----------------------------------------------------------------------*/
  55.  
  56. int
  57. main(int argc, char *argv[])
  58. {
  59.     int i, j, k;
  60.     PLFLT *x, *y, **z;
  61.     PLFLT xx, yy;
  62.  
  63. /* Parse and process command line arguments */
  64.  
  65.     (void) plParseInternalOpts(&argc, argv, PL_PARSE_FULL);
  66.  
  67. /* Initialize plplot */
  68.  
  69.     plinit();
  70.  
  71.     x = (PLFLT *) malloc(XPTS * sizeof(PLFLT));
  72.     y = (PLFLT *) malloc(YPTS * sizeof(PLFLT));
  73.     z = (PLFLT **) malloc(XPTS * sizeof(PLFLT *));
  74.     for (i = 0; i < XPTS; i++) {
  75.     z[i] = (PLFLT *) malloc(YPTS * sizeof(PLFLT));
  76.     x[i] = (double) (i - (XPTS / 2)) / (double) (XPTS / 2);
  77.     }
  78.  
  79.     for (i = 0; i < YPTS; i++)
  80.     y[i] = (double) (i - (YPTS / 2)) / (double) (YPTS / 2);
  81.  
  82.     for (i = 0; i < XPTS; i++) {
  83.     xx = x[i];
  84.     for (j = 0; j < YPTS; j++) {
  85.         yy = y[j];
  86.         z[i][j] = cos(2.0 * PI * xx) * sin(2.0 * PI * yy);
  87.     }
  88.     }
  89.  
  90.     for (k = 0; k < 4; k++) {
  91.     pladv(0);
  92.     plcol(1);
  93.     plvpor(0.0, 1.0, 0.0, 0.8);
  94.     plwind(-1.0, 1.0, -1.0, 1.5);
  95.  
  96.     plw3d(1.0, 1.0, 1.2, -1.0, 1.0, -1.0, 1.0, -1.5, 1.5, alt[k], az[k]);
  97.     plbox3("bnstu", "x axis", 0.0, 0,
  98.            "bnstu", "y axis", 0.0, 0,
  99.            "bcdmnstuv", "z axis", 0.0, 4);
  100.  
  101.     plcol(2);
  102.     plmesh(x, y, z, XPTS, YPTS, opt[k]);
  103.     plcol(3);
  104.     plmtex("t", 1.0, 0.5, 0.5, title[k]);
  105.     }
  106.  
  107.     plend();
  108.     exit(0);
  109. }
  110.